﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Deeper.Common;
using Deeper.Common.Web;
using Deeper.DataAccess;
using @ProjectName@.@ModelNameSpace@;
using @ProjectName@.@ServiceNameSpace@;


namespace @ProjectName@.Web
{
    public partial class @ClassName@Info : Page
    {
        private string OrderBy { get { return  @ClassName@.FieldsName.@Pid@; } }

		protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
				rptList.ReBind();
            }
        }

		protected PageResult MyDataBind(int pageIndex, int pageSize)
		{
			return HDbHelper.GetPageList<@ClassName@>( pageIndex, pageSize, orderby: OrderBy);
		}
      

		protected void  ModelAdd()
		{
			pnlDetail.GetEdit(new @ClassName@());
		}
       
		protected void ModelSave()
		{
			"保存".InfoAction(() =>
			{
				int id = hf@Pid@.Value.ToInt();
                @ClassName@ model = id == 0 ? new @ClassName@() : HDbHelper.GetEntityById<@ClassName@>(id);
                model.GetData(pnlDetail);
                model.Save();
				pnlDetail.Hide();
				rptList.ReBind();
			});
		}


        protected void rptList_Command(object sender, RepeaterCommandEventArgs e)
        {
            int id = e.CommandArgument.ToString().ToInt();
            string cmd = e.CommandName.ToLower();
            switch (cmd)
            {
                case "delete":
                    "删除".InfoAction( () =>
                    {
                     HDbHelper.Delete<@ClassName@>(id);
                     rptList.ReBind();
                    });
                    break;
                case "edit":
                  "获取编辑信息".InfoAction( () =>
                    {
                        pnlDetail.GetEdit(HDbHelper.GetEntityById<@ClassName@>(id));
                    },false);
                    break;
            }

        }
    }


}